//
//  MHCommonViewModel.m
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHCommonViewModel.h"

@implementation MHCommonViewModel

- (void)initialize{
    [super initialize];
    
    @weakify(self);
    /// 选中cell的命令
    /// UI Test
    self.didSelectCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSIndexPath *indexPath) {
        @strongify(self);
        MHCommonGroupViewModel *groupViewModel = self.dataSource[indexPath.section] ;
        MHCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
        
        if (itemViewModel.operation) {
            /// 有操作执行操作
            itemViewModel.operation();
        }else if(itemViewModel.destViewModelClass){
            /// 没有操作就跳转VC
            // 增加参数
            NSDictionary *para =  itemViewModel.model ? @{MHViewModelTitleKey:itemViewModel.title, MHViewModelUtilKey: itemViewModel.model } : @{MHViewModelTitleKey:itemViewModel.title};
            Class viewModelClass = itemViewModel.destViewModelClass;
            
            MHViewModel *viewModel = [[viewModelClass alloc] initWithServices:self.services params:para];
            [self.services pushViewModel:viewModel animated:YES];
        }
        return [RACSignal empty];
    }];
}


@end
